package com.example.quickinjectdemo;

import com.android.bind.QuickBind;
import com.android.bind.annotation.BindLayout;
import com.android.bind.annotation.BindView;
import com.android.bind.annotation.OnCheckedChange;
import com.android.bind.annotation.OnClick;
import com.android.bind.annotation.OnFocusChange;
import com.android.bind.annotation.OnLongClick;
import com.android.bind.annotation.OnPageChange;
import com.android.bind.annotation.OnTouch;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.TextView;

@BindLayout(R.layout.activity_main)
public class MainActivity extends Activity {
	@BindView(R.id.check)
	private CheckBox check;
	@BindView(R.id.text1)
	private TextView mText1;
	@BindView(R.id.text2)
	private TextView mText2;
	@BindView(R.id.text3)
	private TextView mText3;
	@BindView(R.id.viewpager)
	private ViewPager viewpager;

	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.e("MainActivity", "开始时间" + System.currentTimeMillis());
		QuickBind.bind(this);
		Log.e("MainActivity", "结束时间" + System.currentTimeMillis());
		mText1.setText("测试一下");
		mText2.setText("你好啊");
		mText3.setText("测试一下啊  你好啊");
		viewpager.setAdapter(new ImageAdapter());

	}

	@OnTouch(R.id.text1)
	private boolean onTouch(View v, MotionEvent event) {
		Log.e("MainActivity", "测试@OnTouch事件是否触发");
		return false;
	}

	@OnFocusChange({R.id.edit,R.id.edit1})
	private void onFocusChange(View v, boolean hasFocus) {
		Log.e("MainActivity", "测试@OnFocusChange事件是否触发");
	}

	@OnCheckedChange(R.id.check)
	private void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		Log.e("MainActivity", "测试@OnCheckedChange事件是否触发");
		buttonView.setChecked(isChecked);
	}

	@OnClick(R.id.btn_list)
	private void start(View view) {
		Log.e("MainActivity", "测试onClick事件是否触发");
		startActivity(new Intent(MainActivity.this, ListActivity.class));
	}

	@OnLongClick(R.id.btn_list)
	private boolean longClick(View view) {
		Log.e("MainActivity", "长按测试成功");
		return false;
	}

	@OnPageChange(value = R.id.viewpager, callback = "onPageSelected")
	private void onPageSelected(int pos) {
		Log.e("MainActivity", "测试OnPageChange  选中：" + pos);
	}

	class ImageAdapter extends PagerAdapter {

		@Override
		public int getCount() {
			return 4;
		}

		@Override
		public boolean isViewFromObject(View view, Object obj) {
			return view == obj;
		}

		@Override
		public void destroyItem(ViewGroup container, int position, Object object) {
			container.removeView((View) object);
		}

		@Override
		public Object instantiateItem(ViewGroup container, int position) {
			View view = LayoutInflater.from(MainActivity.this).inflate(
					R.layout.item_page, null);
			container.addView(view);
			return view;
		}

	}

}
